package com.tarena.lbs.basic.web.service;

import com.tarena.lbs.basic.web.dao.repository.BussinessCategoryRepository;
import com.tarena.lbs.pojo.basic.po.BusinessCategoryPO;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class BusinessCategoryService {
    @Autowired
    private BussinessCategoryRepository businessCategoryRepository;

    public List<BusinessCategoryVO> list() {
        //1.查询所有分类的PO
        List<BusinessCategoryPO> pos = businessCategoryRepository.list();
        //2.转化返回
        if (pos!=null&&pos.size()>0){
            return pos.stream().map(po->{
                BusinessCategoryVO vo=new BusinessCategoryVO();
                BeanUtils.copyProperties(po,vo);
                return vo;
            }).collect(Collectors.toList());
        }
        return null;
    }
}
